﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.AP.Enums;
using UFIDA.U9.CBO.FI.Enums;
using UFIDA.U9.CBO.SCM.Item;
using UFIDA.U9.SM.ShipPlan;
using UFIDA.U9.SM.SO;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFSoft.UBF.Util.DataAccess;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForShipPlantonull : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //出货计划单
            UFIDA.U9.SM.ShipPlan.ShipPlan sp = key.GetEntity() as UFIDA.U9.SM.ShipPlan.ShipPlan;
            if (sp == null) return;

            #region 复制清空出货计划单:附件清单,单据状态,审批意见
            //清空审批意见
            if (sp.OriginalData.Status == ShipPlanDocStatusEnum.Posted && sp.Status==ShipPlanDocStatusEnum.Open)
            {
                if (sp.DescFlexField.PrivateDescSeg2 != "" || sp.DescFlexField.PrivateDescSeg2 != null)
                {
                    sp.DescFlexField.PrivateDescSeg2 = "";
                }
                //清空附件
                if (sp.DescFlexField.PrivateDescSeg3 != "" || sp.DescFlexField.PrivateDescSeg3 != null)
                {
                    sp.DescFlexField.PrivateDescSeg3 = "";
                }
                //清空oa标识
                if (sp.DescFlexField.PubDescSeg6 != "" || sp.DescFlexField.PubDescSeg6 != null)
                {
                    sp.DescFlexField.PubDescSeg6 = "";
                }
            }
            if ( sp.Status == ShipPlanDocStatusEnum.Open)
            {
                if (sp.DescFlexField.PrivateDescSeg2 != "" || sp.DescFlexField.PrivateDescSeg2 != null)
                {
                    sp.DescFlexField.PrivateDescSeg2 = "";
                }
                //清空附件
                if (sp.DescFlexField.PrivateDescSeg3 != "" || sp.DescFlexField.PrivateDescSeg3 != null)
                {
                    sp.DescFlexField.PrivateDescSeg3 = "";
                }
                //清空oa标识
                if (sp.DescFlexField.PubDescSeg6 != "" || sp.DescFlexField.PubDescSeg6 != null)
                {
                    sp.DescFlexField.PubDescSeg6 = "";
                }
            }
            //单据标识
            if (sp.OriginalData.Status == ShipPlanDocStatusEnum.Open && sp.Status == ShipPlanDocStatusEnum.Posting)
            {
                int n = 1;
                if (sp.DescFlexField.PubDescSeg8 == "")
                {

                    sp.DescFlexField.PubDescSeg8 = n.ToString();
                }
                else
                {
                    sp.DescFlexField.PubDescSeg8 = (decimal.Parse(sp.DescFlexField.PubDescSeg8) + n).ToString();
                }
            }



            #endregion

        }

    }
}
